package me.weijing.common.util;

import me.weijing.common.R;
import android.content.Context;

import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.core.display.BitmapDisplayer;

public class UniversalImageLoader {
    /**
     * 获取ImageLoaderConfiguration
     * 
     * @param context
     * @return
     */
    public static ImageLoaderConfiguration getImageLoaderConfiguration(Context context) {
        ImageLoaderConfiguration mConfiguration = new ImageLoaderConfiguration.Builder(context).threadPriority(Thread.NORM_PRIORITY - 2)
                .denyCacheImageMultipleSizesInMemory().discCacheFileNameGenerator(new Md5FileNameGenerator()).tasksProcessingOrder(QueueProcessingType.LIFO)
                .enableLogging().build();
        return mConfiguration;
    }

    /**
     * 获取ImageOptions
     * 
     * @param displayer
     * @return
     */
    public static DisplayImageOptions getImageOptions(BitmapDisplayer displayer) {
        DisplayImageOptions options = new DisplayImageOptions.Builder().cacheInMemory().cacheOnDisc().showImageOnFail(R.drawable.default_img_bad)
                .imageScaleType(ImageScaleType.IN_SAMPLE_INT).build();
        return options;
    }
}
